package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmMaterialDto;
import com.heima.media.entity.WmMaterial;
import com.heima.media.service.IWmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 自媒体图文素材信息表 前端控制器
 * </p>
 *
 * @author wsj
 * @since 2022-03-11
 */
@RestController
@RequestMapping("/api/v1/material")
@Api(tags = "自媒体图文素材信息表接口")
public class WmMaterialController{

    @Autowired
    private IWmMaterialService wmMaterialService;

    /**
     * 素材图片保存
     * @param file
     * @return
     */
    @ApiOperation(value = "素材图片保存",notes = "author:wsj")
    @ApiImplicitParam(name = "file",value = "素材图片",required = true,dataType = "MultipartFile")
    @PostMapping("/upload_picture")
    public ResponseResult<WmMaterial> upload(MultipartFile file) {
        return wmMaterialService.upload(file);
    }

    /**
     * 素材图片分页列表
     * @param dto
     * @return
     */
    @ApiOperation(value = "素材图片分页列表",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "查询对象",required = true,dataType = "WmMaterialDto")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.listByPage(dto);
    }

    /**
     * 收藏素材
     * @param id
     * @return
     */
    @PutMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id) {
        return wmMaterialService.collect(id);
    }

    /**
     * 取消收藏素材
     * @param id
     * @return
     */
    @PutMapping("/cancel_collect/{id}")
    public ResponseResult collectCancel(@PathVariable("id") Integer id) {
        return wmMaterialService.collectCancel(id);
    }

    /**
     * 删除素材
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        return wmMaterialService.delete(id);
    }
}
